package com.chuangjiangx.member.basic.web.config;

import com.chuangjiangx.member.basic.web.websocket.MemberCodePayWebSocketHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * Created by junn on 16-11-15.
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //会员支付界面webSocket
        registry.addHandler(memberCodePayWebSocketHandler(), "/member/webSocketServer")
                .setAllowedOrigins("*");
//        registry.addHandler(memberCodePayWebSocketHandler(), "/member/member-pay-code/sockjs")
//                .setAllowedOrigins("*")
//                .withSockJS();
    }

    @Bean
    public WebSocketHandler memberCodePayWebSocketHandler() {
        return new MemberCodePayWebSocketHandler();
    }
}